package com.shushan.invitecode;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.shushan.base.BaseActivity;
import com.shushan.base.ScreenManager;
import com.shushan.shushanbao.BabyApplication;
import com.shushan.shushanbao.R;

/**
 * @ClassName: MyInviteCodeActivity
 * @Desciption: //我的邀请码界面
 * @author: zhangshihao
 * @date: 2018-09-15
 */
public class MyInviteCodeActivity extends BaseActivity implements View.OnClickListener{

    private static final String TAG = MyInviteCodeActivity.class.getSimpleName();

    private Button btnCopy;
    private TextView tvInviteCode;

    private ClipboardManager clipboardManager;

    private BabyApplication babyApplication = BabyApplication.getInstance();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ScreenManager.getInstance().setStatusBar(true,this);
        setContentView(R.layout.activity_my_invite_code);

        initView();
    }

    private void initView(){
        btnCopy = findViewById(R.id.btn_copy);
        btnCopy.setOnClickListener(this);
        tvInviteCode = findViewById(R.id.tv_invite_code);
        tvInviteCode.setText(babyApplication.getInviteCode());
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.btn_copy:
                if(clipboardManager == null) {
                    clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                }
                ClipData myClip;
                myClip = ClipData.newPlainText("inviteCode", babyApplication.getInviteCode());
                clipboardManager.setPrimaryClip(myClip);
                showToast("邀请码复制成功");
                break;
        }
    }

}
